<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>getdate</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_005_497">&nbsp;</a>NAME</h4><blockquote>
getdate - convert user format date and time
</blockquote><h4><a name = "tag_000_005_498">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="time.h.html">time.h</a>&gt;

struct tm *getdate(const char *<i>string</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_005_499">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>getdate()</i>
function converts a string representation of a date or time into a broken-down
time.
<p>
The external variable or macro
<i>getdate_err</i>
is used by
<i>getdate()</i>
to return error values.
<p>
Templates are used to parse and interpret the input string.  The templates are
contained in a text file identified by the environment variable
<i>DATEMSK</i>.
The
<i>DATEMSK</i>
variable should be
set to indicate the full pathname of the file that contains the templates.
The first line in the template that matches the input specification is used
for interpretation and conversion into the internal time format.
<p>
The following field descriptors are supported:
<dl compact>

<dt>%%<dd>same as %

<dt>%a<dd>abbreviated weekday name

<dt>%A<dd>full weekday name

<dt>%b<dd>abbreviated month name

<dt>%B<dd>full month name

<dt>%c<dd>locale's appropriate date and time representation

<dt>%C<dd>century number (00-99; leading zeros are permitted but not
required)

<dt>%d<dd>day of month (01-31; the leading 0 is optional)

<dt>%D<dd>date as %m/%d/%y

<dt>%e<dd>same as %d

<dt>%h<dd>abbreviated month name

<dt>%H<dd>hour (00-23)

<dt>%I<dd>hour (01-12)

<dt>%m<dd>month number (01-12)

<dt>%M<dd>minute (00-59)

<dt>%n<dd>same as new line

<dt>%p<dd>locale's equivalent of either AM or PM

<dt>%r<dd>The locale's appropriate representation of time in AM and PM notation.  In
the POSIX locale, this is equivalent to %I:%M:%S %p

<dt>%R<dd>time as %H:%M

<dt>%S<dd>seconds (00-61).  Leap seconds are allowed but are not predictable through use
of algorithms.

<dt>%t<dd>same as tab

<dt>%T<dd>time as %H:%M:%S

<dt>%w<dd>weekday number (Sunday = 0 - 6)

<dt>%x<dd>locale's appropriate date representation

<dt>%X<dd>locale's appropriate time representation

<dt>%y<dd>year within century.
When a century is not otherwise specified,
values in the range 69-99 refer to years in
the twentieth century (1969 to 1999 inclusive); values in the range 
00-68 refer to years in the twenty-first century (2000 to 2068
inclusive).

<dt>%Y<dd>year as ccyy (for example, 1994)

<dt>%Z<dd>time zone name or no characters if no time zone exists.  If the time zone
supplied by %Z is not the time zone that
<i>getdate()</i>
expects, an invalid input specification error will result.  The
<i>getdate()</i>
function calculates an expected time zone based on information supplied to the
function (such as the hour, day, and month).

</dl>
<p>
The match between the template and input specification performed by
<i>getdate()</i>
is case insensitive.
<p>
The month and weekday names can consist of any combination
of upper and lower case letters.
The process can request that the input date or time specification
be in a specific language by setting the LC_TIME category (see
<i><a href="setlocale.html">setlocale()</a></i>).
<p>
Leading 0's are not necessary for the descriptors that allow leading 0's.
However, at most two digits are allowed for those descriptors, including
leading 0's.  Extra whitespace in either the template file or in <i>string</i>
is ignored.
<p>
The field descriptors %c, %x, and %X will not be supported if they include
unsupported field descriptors.
<p>
The following rules apply for converting the input specification into the
internal format:
<ul>
<p>
<li>
If %Z is being scanned, then
<i>getdate()</i>
initialises the broken-down time to be the current time in the scanned time
zone.
Otherwise it initialises the broken-down time
based on the current local time as if
<i><a href="localtime.html">localtime()</a></i>
had been called.
<p>
<li>
If only the weekday is given, today is assumed if the given day is equal to
the current day and next week if it is less,
<p>
<li>
If only the month is given, the current month is assumed if the given month is
equal to the current month and next year if it is less and no year is given
(the first day of month is assumed if no day is given),
<p>
<li>
If no hour, minute and second are given the current hour, minute and second
are assumed,
<p>
<li>
If no date is given, today is assumed if the given hour is greater than the
current hour and tomorrow is assumed if it is less.
<p>
</ul>
<p>
If a field descriptor specification in the DATEMSK file does not
correspond to one of the field descriptors above, the behaviour is
unspecified.
<p>
This interface need not be reentrant.
</blockquote><h4><a name = "tag_000_005_500">&nbsp;</a>RETURN VALUE</h4><blockquote>
Upon successful completion,
<i>getdate()</i>
returns a pointer to a <b>struct&nbsp;tm</b>.  Otherwise, it returns a null pointer
and <i>getdate_err</i> is set to indicate the error.
</blockquote><h4><a name = "tag_000_005_501">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>getdate()</i>
function will fail in the following cases, setting
<i>getdate_err</i>
to the value shown in the list below.  Any changes to
<i>errno</i>
are unspecified.
<dl compact>

<dt>1<dd>The
<i>DATEMSK</i>
environment variable is null or undefined.

<dt>2<dd>The template file cannot be opened for reading.

<dt>3<dd>Failed to get file status information.

<dt>4<dd>The template file is not a regular file.

<dt>5<dd>An I/O error is encountered while reading the template file.

<dt>6<dd>Memory allocation failed (not enough memory available).

<dt>7<dd>There is no line in the template that matches the input.

<dt>8<dd>Invalid input specification.  For example, February 31; or a time is specified
that can not be represented in a <b>time_t</b> (representing the time in
seconds since 00:00:00 UTC, January 1, 1970).

</dl>
</blockquote><h4><a name = "tag_000_005_502">&nbsp;</a>EXAMPLES</h4><blockquote>
Example 1:
<p>
The following example shows the possible contents of a template:
<pre>
<code>
%m
%A %B %d, %Y, %H:%M:%S
%A
%B
%m/%d/%y %I %p
%d,%m,%Y %H:%M
at %A the %dst of %B in %Y
run job at %I %p,%B %dnd
%A den %d. %B %Y %H.%M Uhr
</code>
</pre>
<p>
Example 2:
<p>
The following are examples of valid input specifications for
the template in Example 1:
<pre>
<code>
getdate("10/1/87 4 PM");
getdate("Friday");
getdate("Friday September 18, 1987, 10:30:30");
getdate("24,9,1986 10:30");
getdate("at monday the 1st of december in 1986");
getdate("run job at 3 PM, december 2nd");
</code>
</pre>
<p>
If the LC_TIME
category is set to a German locale that includes freitag as a weekday
name and oktober as a month name, the following would be valid:
<pre>
<code>
getdate("freitag den 10. oktober 1986 10.30 Uhr");
</code>
</pre>
<p>
Example 3:
<p>
The following examples shows how local date and time specification can be
defined in the template.
<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Invocation</b>
<th align=center><b>Line in Template</b>
<tr valign=top><td align=center>getdate("11/27/86")
<td align=center>%m/%d/%y
<tr valign=top><td align=center>getdate("27.11.86")
<td align=center>%d.%m.%y
<tr valign=top><td align=center>getdate("86-11-27")
<td align=center>%y-%m-%d
<tr valign=top><td align=center>getdate("Friday 12:00:00")
<td align=center>%A %H:%M:%S
</table>
<p>
Example 4:
<p>
The following examples help to illustrate the above
rules assuming that the current date is
Mon Sep 22 12:19:47 EDT 1986
and the LC_TIME
category is set to the default "C" locale.
<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Input</b>
<th align=center><b>Line in Template</b>
<th align=center><b>Date</b>
<tr valign=top><td align=center>Mon
<td align=center>%a
<td align=left>Mon Sep 22 12:19:47 EDT 1986
<tr valign=top><td align=center>Sun
<td align=center>%a
<td align=left>Sun Sep 28 12:19:47 EDT 1986
<tr valign=top><td align=center>Fri
<td align=center>%a
<td align=left>Fri Sep 26 12:19:47 EDT 1986
<tr valign=top><td align=center>September
<td align=center>%B
<td align=left>Mon Sep  1 12:19:47 EDT 1986
<tr valign=top><td align=center>January
<td align=center>%B
<td align=left>Thu Jan  1 12:19:47 EST 1987
<tr valign=top><td align=center>December
<td align=center>%B
<td align=left>Mon Dec  1 12:19:47 EST 1986
<tr valign=top><td align=center>Sep Mon
<td align=center>%b %a
<td align=left>Mon Sep  1 12:19:47 EDT 1986
<tr valign=top><td align=center>Jan Fri
<td align=center>%b %a
<td align=left>Fri Jan  2 12:19:47 EST 1987
<tr valign=top><td align=center>Dec Mon
<td align=center>%b %a
<td align=left>Mon Dec  1 12:19:47 EST 1986
<tr valign=top><td align=center>Jan Wed 1989
<td align=center>%b %a %Y
<td align=left>Wed Jan  4 12:19:47 EST 1989
<tr valign=top><td align=center>Fri 9
<td align=center>%a %H
<td align=left>Fri Sep 26 09:00:00 EDT 1986
<tr valign=top><td align=center>Feb 10:30
<td align=center>%b %H:%S
<td align=left>Sun Feb  1 10:00:30 EST 1987
<tr valign=top><td align=center>10:30
<td align=center>%H:%M
<td align=left>Tue Sep 23 10:30:00 EDT 1986
<tr valign=top><td align=center>13:30
<td align=center>%H:%M
<td align=left>Mon Sep 22 13:30:00 EDT 1986
</table>
</blockquote><h4><a name = "tag_000_005_503">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
Although historical versions of
<i>getdate()</i>
did not require that
<i><a href="time.h.html">&lt;time.h&gt;</a></i>
declare the external variable
<i>getdate_err</i>,
this specification does require it.
The Open Group encourages applications to remove declarations of
<i>getdate_err</i>
and instead incorporate the declaration by including
<i><a href="time.h.html">&lt;time.h&gt;</a></i>.
<p>
Applications should use %Y (4-digit years) in preference to %y
(2-digit years).
</blockquote><h4><a name = "tag_000_005_504">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_505">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="ctime.html">ctime()</a></i>,
<i><a href="localtime.html">localtime()</a></i>,
<i><a href="setlocale.html">setlocale()</a></i>,
<i><a href="strftime.html">strftime()</a></i>,
<i><a href="times.html">times()</a></i>,
<i><a href="time.h.html">&lt;time.h&gt;</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
